<template>
  <div class="order">
    <div class="top">
      <span><i class="el-icon-tickets"></i>我的订单</span>
    </div>
    <!-- 商品 -->
    <div class="information" v-for="(item,index) in list" :key="index">
      <p><span>订单编号：{{item[0].order_id}}</span><span>订单时间:2022-07-31 20:28:39</span></p>
      <div>
        <div class="tite">
          <span>商品名称</span>
          <span class="pro-price">单价</span>
          <span class="pro-num">数量</span>
          <span class="pro-total">小计</span>
        </div>
        <ul>
          <li v-for="(itme,ins) in list[index]" :key="ins">
            <span><img :src="` http://101.132.181.9:3000/${itme.product_picture}`" alt=""></span>
            <span class="pro-name">{{itme.product_name}}</span>
            <span class="pro-price">{{itme.product_price}}元</span>
            <span class="pro-num">{{itme.product_num}}</span>
            <span class="pro-total">{{itme.pay}}元</span>
            <!--  -->
          </li>
        </ul>
        <div class="bott">
          <div>共<span class="h">{{list[index].length}}</span>件商品</div>
          <div class="h">合计<span class="hh">{{item.all}}元</span></div>
        </div>
      </div>
    </div>
    <!-- 空状态 -->
    <div class="Empty" v-show="list == '[]'">
      <p>您的订单还是空的！</p>
      <span>快去购物吧！</span>
    </div>
  </div>
</template>
<script setup>
import { orderid } from '@/utils/last.js'
import {ref,onMounted,computed,watch} from 'vue'

const num = computed(()=>{
    var num = 0;
    list.value.forEach((item,index) => {
        // console.log(item);
        // item.pid = index;
        item.forEach((it,ins) => {
            // it.pid = index;
            // console.log(it.pid,ins);
            if(ins == 0){
                // console.log('新',it.product_num*it.product_price);
            }else{
                // console.log('组',it.product_num*it.product_price);
            }
        })
    })
        return num
})

  const user_id=ref(0);
    const list = ref([]);
    const getOrder = async ()=>{
        user_id.value = localStorage.getItem('user_id');
        let data = await orderid({ user_id:user_id.value });
        // console.log(data);
        list.value = data.orders;
    }
    
watch(list,(val)=>{
    var num = 0;
        val.forEach((item,index)=>{
        item.all = 0;
        item.forEach((it,ins)=>{
            it.pid = index;
            it.pay = it.product_num*it.product_price;
            item.all += it.pay;
        })
    })
    },{
        deep:true,
        immediate:true
})
onMounted(() => {
        getOrder();
    
})
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
.order {
  background: #f5f5f5;
}
.information {
  background: #fff;
  width: 1225px;
  margin: 0 auto;
  p {
    padding: 0 26px;
    border-bottom: 1px solid #ffc095;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    height: 60px;
    align-items: center;
    & > span:first-child {
      color: #ff6a18;
    }
  }
}
.top {
  width: 100%;
  height: 64px;
  background: #fff;
  border-bottom: 2px solid #ff6700;
  span {
    display: block;
    width: 1225px;
    margin: 0 auto;
    font-size: 28px;
    line-height: 64px;
    i {
      font-size: 28px;
      color: #ff6700;
      margin-right: 10px;
    }
  }
}
ul {
  width: 1199px;
  li {
    width: 100%;
    height: 85px;
    padding: 15px 26px 15px 80px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    img {
      width: 80px;
      height: 80px;
    }
    span {
      display: inline-block;
      margin-left: 30px;
    }
    .pro-name {
      width: 380px;
      height: 85px;
      line-height: 85px;
    }
    .pro-price {
      width: 160px;
    }
    .pro-num {
      width: 190px;
    }
    .pro-total {
      width: 160px;
    }
  }
}
.bott {
  width: 1199px;
  height: 85px;
  display: flex;
  justify-content: space-between;
  line-height: 85px;
  border-top: 1px solid #ff6a04;
  box-sizing: border-box;
  padding: 0 20px;
  margin-bottom: 50px;
  .h {
    color: #ff6a04;
  }
  .hh {
    color: #ff6a04;
    font-size: 30px;
  }
}
.tite {
  width: 1199px;
  height: 85px;
  line-height: 85px;
  padding: 0 26px 0 0;
  span {
    display: inline-block;
    margin-left: 30px;
  }
  .pro-price {
    width: 160px;
  }
  .pro-num {
    width: 190px;
  }
  .pro-total {
    width: 160px;
  }
  & > span:first-child {
    width: 390px;
    margin-left: 202px;
  }
}
.Empty {
  width: 1199px;
  height: 300px;
  padding: 0 0 130px 300px;
  box-sizing: border-box;
  margin-top: 65px;
  img {
    height: 250px;
    float: left;
    margin-right: 30px;
  }
  p {
    margin: 70px 0 15px;
    font-size: 36px;
    color: #b0b0b0;
    display: inline-block;
  }
  span {
    margin: 0 0 20px;
    font-size: 20px;
    color: #b0b0b0;
    display: block;
  }
}
</style>